var handle = {

    add: function (id) {
        openWindow((id == undefined ? "新增" : "编辑" ) + '角色',  "/roleManage/toAdd?" + (id == undefined ? "" : "roleId=" + id ), 800, 400);
    },

    view: function (id) {
        openDialogView('查看', "/roleManage/view?" + (id == undefined ? "" : "roleId=" + id ), 800, 400);
    },
    authRole: function (id) {
        openWindow("权限设置", '/roleManage/setPower?roleId=' + id, 700, 500);
    },
    assignRole: function (id) {
        openDialogView("分配用户", '/roleManage/assign?roleId=' + id, 800, 600);
    },

    del: function (id) {
        layer.confirm('确认删除吗？相关的用户角色，菜单角色关系也会删除', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            layer.closeAll();
            Public.ajaxPost("roleManage/removeRoles", {
                roleId: id
            }, function (result) {
                if (result && 0 == result.code) {
                    layer.msg("操作成功!", {icon: 1});
                    func.reloadData();
                } else {
                    layer.msg(result.message, {icon: 2});
                    return;
                }
            });
        });
    }
};

var func = {
    reloadData: function (t) {
        $("#datatable").jqGrid("setGridParam", {
            url: "/roleManage/tableShow",
            datatype: "json", mtype: 'POST',
            postData: t
        }).trigger("reloadGrid");
    }
};
